<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/10/7
 * Time: 10:49
 */
namespace app\admin\controller;
use think\Db;
class Money extends Base
{
    public function tixianAgreeShopOrWork($number,$money,$phone,$name,$remark='')
//    public function tixianAgreeShopOrWork()
    {
        header("Content-type:text/html;charset=UTF-8");
//        $number='444555661313131316';
//        $money='0.1';
//        $phone='15895980214';
//        $name='麻威我';
//        $remark = '';
        import('alipay.aop.AopClient',EXTEND_PATH);
        import('alipay.aop.request.AlipayFundTransToaccountTransferRequest',EXTEND_PATH);
        $aop = new \AopClient;
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = '2018090761306686';
        $aop->rsaPrivateKey = 'MIIEpQIBAAKCAQEA2b4GAsKv3MXAgKvPAVHJeT0MZ+XX5Ke55q74ecV/Wy9NN7wmJBUEVqf/jZEaCtxEhNUNjz74XyoTN/xvYeZ2sjtMSmCzjAuvUUM5GlAMvwg+UpIWC95J1Sz3eLOfzciPUhcd2A4yCEHXjjlgOfWB25U8HBYr8kddfHGm5sKC3IiGM88GLu4CM9MSjdDtvMOeQOh4Zptq9Gz5FVA1BO1nvd4Eb3iUyy3xeVWrYRd1NkSdHJ+TGqEOGIa9X4qtZPcwK5T9Q0I1b7QYt1JuV0j5iizDqP79qMHhX/Hmw+abmJAKM7wfNdS85NXQh+Lkdi7X0qvCzUT7pUsded6YtKYpCQIDAQABAoIBAQDKjwr6cHC3mcN+L9Zv7MzXm2I6GUihLyMypZ0DcyYKBtP3wHFe6apSjxCeetjWN5kKVUS6+KKHrRWZ5J0dXw8WuTE8k/8Tjh83IqkxgDyLTjjkCYC248Cdrqo9QCSuhCBIBrc9sd77bX0AkwGgiXKXepojqsCRL7CZPwU78MFaM3QVUimLYASE9Q6/Z3jhbEUuSK7uU96vOD+mfYVCMtohLqGx2Tk/uMFeHxpS6E/HSsgfGUJHCufFA62nwsE2tAMEfZChFJIWKSqy4CWCbgWM82AvihK94CRsAvpkROVqcB4PY0Q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wIz4BMjPCb+0Yqnn+Zuk+hoJQtcXdj+q4lEvvbOvTKm7aHVE2TdL62kXB6WVvc1Tk2jSFg1yO7ljvsbZuFq+b24VyOR6h8cXyUBpeoptlmpVk/Q3rbDltuE+PinOXgVQVKkjKBrKx9j1tl8MZrMOsCEgxYNNmi0ycJqfa3NSPunYsocld/xo39OVAZ7ophZi3dwpBIHOmqHbI+6hf90H/FHcMhERL5OnURX/t+GX4+LOl1/R0U6uQIDAQAB';
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        $request = new \AlipayFundTransToaccountTransferRequest;
        $request->setBizContent("{" .
            "\"out_biz_no\":\"".$number."\"," .
            "\"payee_type\":\"ALIPAY_LOGONID\"," .
            "\"payee_account\":\"".$phone."\"," .
            "\"amount\":\"".$money."\"," .
            "\"payer_show_name\":\"红集提现到账\"," .
            "\"payee_real_name\":\"".$name."\"," .
            "\"remark\":\"".$remark."\"" .
            "}");
        $result = $aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
            $result = array();
            $result['status'] = 200;
            $result['msg'] = 'OK';
            return $result;
        } else {
            $result = array();
            $result['status'] = 0;
            $result['msg'] = $result->alipay_fund_trans_toaccount_transfer_response->sub_msg;
            return $result;
        }
    }
    public function chaxunTixianRes($number)
    {
        header("Content-type:text/html;charset=UTF-8");
        import('alipay.aop.AopClient',EXTEND_PATH);
        import('alipay.aop.request.AlipayFundTransOrderQueryRequest',EXTEND_PATH);
        $aop = new \AopClient;
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = '2018090761306686';
        $aop->rsaPrivateKey = 'MIIEpQIBAAKCAQEA2b4GAsKv3MXAgKvPAVHJeT0MZ+XX5Ke55q74ecV/Wy9NN7wmJBUEVqf/jZEaCtxEhNUNjz74XyoTN/xvYeZ2sjtMSmCzjAuvUU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bZ5JRVxbyZZOh1qXTWfejga1KtkSPHbTatsZE97HmnmBxajQUWDbnvlG9jJgTAoGBAJhTa79nXOuX8IerBBFSjz1DxTOmsIGWs5tIWQah1DwfmqB/9QZQY2xj7omcIlD990azQ6Kg1wryFU+Q1bh99PCobTT+FDIq7zrCDXQgK3t8mPWiirXVT4T1gSx76/pIN4mFlPFC9OxaXc3KLPj7bP+Omf2z1rbaKh6qlP+4ZZ7tAoGASU7kUHm/o35qU8Sy9f0YSeOq4JRMast8tyj7hqI5ZEb4LCHioFpK76qmUHrsgAXO48NeQ0AZPsNA7jqYVEPHemcpk+Qzva0VkinUhSb+Hvqeam314lQpg0ctpJf73yjIy9ScxCFxNnoDLybWnbptazW3OwhKNdyVQ675kp/GXVU=';
        $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl52A0hQejykjLpsxv5Bp4pHlri3GFYdzHtHpk33yKZKuFglgwVm/xTxur+6wKKYssyBfBXwP7vibn+JNw/yg0WuYYpv41PIUmwIz4BMjPCb+0Yqnn+Zuk+hoJQtcXdj+q4lEvvbOvTKm7aHVE2TdL62kXB6WVvc1Tk2jSFg1yO7ljvsbZuFq+b24VyOR6h8cXyUBpeoptlmpVk/Q3rbDltuE+PinOXgVQVKkjKBrKx9j1tl8MZrMOsCEgxYNNmi0ycJqfa3NSPunYsocld/xo39OVAZ7ophZi3dwpBIHOmqHbI+6hf90H/FHcMhERL5OnURX/t+GX4+LOl1/R0U6uQIDAQAB';
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        $request = new \AlipayFundTransOrderQueryRequest;
        $request->setBizContent("{" .
            "\"out_biz_no\":\"".$number."\"" .
            "  }");
        $result = $aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
            return true;
        } else {
            return false;
        }
    }


    public function WeChatPayReady($order,$type=null){
        // 获取配置项
        $data=array(
            'appid'=>$weixinpay_config2['APPID'],
            'mch_id'=>$weixinpay_config2['MCHID'],
            'nonce_str'=>'test',
            'spbill_create_ip'=>$_SERVER['REMOTE_ADDR'],
            'notify_url'=>$weixinpay_config2['NOTIFY_URL']
        );
        // 生成签名
        $sign=$this->makeSign($data);
        $data['sign']=$sign;
        $xml=$this->toXml($data);
        $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';//接收xml数据的文件
        $header[] = "Content-type: text/xml";//定义content-type为xml,注意是数组
        $ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);//严格校验
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        $response = curl_exec($ch);
        if(curl_errno($ch)){
            print curl_error($ch);
        }
        curl_close($ch);
        $result=$this->toArray($response);
        if($result['return_code'] == 'FAIL'){
            $returnerr['msg'] = $result['return_msg'];
            $returnerr['type'] = 'error';
            return $returnerr;
        }else{
            $result['sign']=$sign;
            $result['nonce_str']='test';
            $result2 = $this->getOrder($result['prepay_id']);
            return $result2;///
        }

    }
    /**
     * 生成签名
     * @return 签名，本函数不覆盖sign成员变量，如要设置签名需要调用SetSign方法赋值
     */
    public function makeSign($data){
        // 去空
        $data=array_filter($data);
        //签名步骤一：按字典序排序参数
        ksort($data);
        $string_a=http_build_query($data);
        $string_a=urldecode($string_a);
        //签名步骤二：在string后加入KEY
        $config2=$this->config2;
        $string_sign_temp=$string_a."&key=".$config2['KEY'];
        //签名步骤三：MD5加密
        $sign = md5($string_sign_temp);
        // 签名步骤四：所有字符转为大写
        $result=strtoupper($sign);
        return $result;
    }
    /**
     * 输出xml字符
     * @throws WxPayException
     **/
    public function toXml($data){
        //var_dump($data);
        if(!is_array($data) || count($data) <= 0){
            //throw new WxPayException("数组数据异常！");
        }
        $xml = "<xml>";
        foreach ($data as $key=>$val){
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        return $xml;
    }
    /**
     * 将xml转为array
     * @param  string $xml xml字符串
     * @return array       转换得到的数组
     */
    public function toArray($xml){
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $result= json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $result;
    }
    //获取指定长度的随机字符串
    function getRandChar($length){
        $str = null;
        $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        $max = strlen($strPol)-1;

        for($i=0;$i<$length;$i++){
            $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
        }

        return $str;
    }

//    /**   原支付宝提现，打开即用
//     * r_id,type 1是同意 2是拒绝,remark(备注)
//     * @return \think\response\Json
//     */
//    public function agreeOrRefuseTixian($r_id,$type,$remark)
//    {
//        $jilu = Db::name('work_jilu')->where('r_id',$r_id)->find();
//        if($jilu['r_status'] != 1){
//            return ['code'=>0,'msg'=>'已经操作过了，请刷新！'];
//        }else{
//            $today = date('Y-m-d H:i:s');
//            if($type == 1){//同意
//                $have = $this->chaxunTixianRes($jilu['r_water']);
//                if($have){
//                    return ['code'=>0,'msg'=>'此订单号已经体现过了'];
//                }else{
//                    $res = $this->tixianAgreeShopOrWork($jilu['r_water'],$jilu['r_money'],$jilu['r_acc_num'],$jilu['r_acc_username'],$remark);
//                    if($res['status'] == 200){
//                        $last = Db::name('work_jilu')->where('r_id',$r_id)
//                            ->update(['r_status'=>2,'r_remark'=>$remark,'r_res'=>2,'r_dotime'=>$today]);//r_res没用。。。
//                        if($last){
//                            //入消息和推送
//                            if ($jilu['r_type'] == 1) {//商户
//                                $where = 2;
//                            } else {
//                                $where = 3;
//                            }
//                            //消息和推送
//                            allInNotice('提现到账通知','您申请的'.$jilu['r_money'].'元的提现，已到账，请注意查收',$jilu['r_user_id']);
//                            sendJpush("{$jilu['r_user_id']}", '您申请的'.$jilu['r_money'].'元的提现，已到账，请注意查收', array('a' => 'b'), 2, 2, $where);
//                            return ['code'=>200,'msg'=>'操作成功'];
//                        }else{
//                            return ['code'=>0,'msg'=>'提现成功但状态更改失败，请忽略此申请！'];
//                        }
//                    }else{
//                        return ['code'=>0,'msg'=>$res['msg']];
//                    }
//                }
//            }else{
//                Db::startTrans();
//                try {
//                    Db::name('work_jilu')->where('r_id', $r_id)
//                        ->update(['r_status' => 3, 'r_remark' => $remark, 'r_res' => 3,'r_dotime'=>$today]);//r_res没用。。。
//                    if ($jilu['r_type'] == 1) {//商户
//                        $where = 2;
//                        Db::table('up_shops')->where('s_id', $jilu['r_user_id'])->setInc('s_money', $jilu['r_money']);
//                    } else {
//                        $where = 3;
//                        Db::table('up_work_user')->where('user_id', $jilu['r_user_id'])->setInc('user_money', $jilu['r_money']);
//                    }
//                    Db::commit();
//                    //消息和推送
//                    allInNotice('提现驳回通知','您申请的'.$jilu['r_money'].'元的提现申请被驳回，原因：'.$remark,$jilu['r_user_id']);
//                    sendJpush("{$jilu['r_user_id']}", '您申请的'.$jilu['r_money'].'元的提现申请被驳回', array('a' => 'b'), 2, 2, $where);
//                    return ['status' => 200, 'msg' => '操作成功'];
//                } catch (\Exception $e) {
//                    Db::rollback();
//                    return ['status' => 0, 'msg' => '操作失败'];
//                }
//            }
//        }
//    }

    /**
     * r_id,type 1是同意 2是拒绝,remark(备注)
     * @return \think\response\Json
     */
    public function agreeOrRefuseTixian($r_id,$type,$remark)
    {
        $jilu = Db::name('work_jilu')->where('r_id',$r_id)->find();
        if($jilu['r_where'] == 1){
            if($jilu['r_status'] != 1){
                return ['code'=>0,'msg'=>'已经操作过了，请刷新！'];
            }else{
                $today = date('Y-m-d H:i:s');
                if($type == 1){//同意
                    $last = Db::name('work_jilu')->where('r_id',$r_id)
                        ->update(['r_status'=>2,'r_remark'=>$remark,'r_res'=>2,'r_dotime'=>$today]);//r_res没用。。。
                    if($last){
                        //入消息和推送
                        if ($jilu['r_type'] == 1) {//商户
                            $where = 2;
                        } else {
                            $where = 3;
                        }
                        //消息和推送
                        allInNotice('提现到账通知','您申请的'.$jilu['r_money'].'元的提现，已到账，请注意查收',$jilu['r_user_id']);
                        sendJpush("{$jilu['r_user_id']}", '您申请的'.$jilu['r_money'].'元的提现，已到账，请注意查收', array('a' => 'b'), 2, 2, $where);
                        return ['code'=>200,'msg'=>'操作成功'];
                    }else{
                        return ['code'=>0,'msg'=>'操作失败！'];
                    }
                }else{
                    Db::startTrans();
                    try {
                        Db::name('work_jilu')->where('r_id', $r_id)
                            ->update(['r_status' => 3, 'r_remark' => $remark, 'r_res' => 3,'r_dotime'=>$today]);//r_res没用。。。
                        if ($jilu['r_type'] == 1) {//商户
                            $where = 2;
                            Db::table('up_shops')->where('s_id', $jilu['r_user_id'])->setInc('s_money', $jilu['r_money']);
                        } else {
                            $where = 3;
                            Db::table('up_work_user')->where('user_id', $jilu['r_user_id'])->setInc('user_money', $jilu['r_money']);
                        }
                        Db::commit();
                        //消息和推送
                        allInNotice('提现驳回通知','您申请的'.$jilu['r_money'].'元的提现申请被驳回，原因：'.$remark,$jilu['r_user_id']);
                        sendJpush("{$jilu['r_user_id']}", '您申请的'.$jilu['r_money'].'元的提现申请被驳回', array('a' => 'b'), 2, 2, $where);
                        return ['status' => 200, 'msg' => '操作成功'];
                    } catch (\Exception $e) {
                        Db::rollback();
                        return ['status' => 0, 'msg' => '操作失败'];
                    }
                }
            }
        }else{
            return ['status' => 0, 'msg' => '暂未开放支付宝和微信提现'];
        }
    }


    /*
     * 商户提现
     */
    public function businessMoney()
    {
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($key)&&$key!="")
            {
                $map['user_username|r_water'] = ['like',"%" . $key . "%"];
            }
            $map['r_type'] = 1;
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('work_jilu j')
                ->join('shops u','u.s_id = j.r_user_id','left')
                ->where($map)
                ->count();
            $lists = Db::name('work_jilu j')
                ->join('shops u','u.s_id = j.r_user_id','left')
                ->field('r_id,s_name as user_username,r_money,r_status,r_acc_bank,r_time,r_water,r_acc_num,r_acc_username,r_where')
                ->where($map)
                ->page($Nowpage,$limits)
                ->order('r_time desc')
                ->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('money/business_money');
    }

    /*
     * 商户提现
     */
    public function getShopMoney(){
        extract(input());
        $res = $this->agreeOrRefuseTixian($r_id,$type,$remark);
        return json($res);
    }

    /*
     * 商户批量提现
     */
    public function shopBatchMoney(){
        extract(input());
        if($r_id == ''){
            return json(['code'=>100,'msg'=>'请选择要提现的记录！']);
        }
        $ids = explode(',',$r_id);
        foreach($ids as $key=>$vo){
            $res = $this->agreeOrRefuseTixian($vo,$type,$remark);
            if($res['code'] != 200){
                return json(['code'=>100,'msg'=>'ID:'.$vo.'商户提现失败']);
            }
        }
        return json(['code'=>200,'msg'=>'批量提现成功']);
    }

    /*
     * 业务员提现
     */
    public function salesmanMoney()
    {
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($key)&&$key!="")
            {
                $map['user_name|r_water'] = ['like',"%" . $key . "%"];
            }
            $map['r_type'] = 2;
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('work_jilu j')
                ->join('work_user u','u.user_id = j.r_user_id','left')
                ->where($map)
                ->count();
            $lists = Db::name('work_jilu j')
                ->join('work_user u','u.user_id = j.r_user_id','left')
                ->field('r_id,user_name,r_money,r_status,r_acc_bank,r_time,r_water,r_acc_num,r_acc_username,r_where')
                ->where($map)
                ->page($Nowpage,$limits)
                ->order('r_time desc')
                ->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('money/salesman_money');
    }

    /*
     * 业务员提现
     */
    public function getSaleMoney(){
        extract(input());
        $res = $this->agreeOrRefuseTixian($r_id,$type,$remark);
        return json($res);
    }

    /*
    * 业务员批量提现
    */
    public function shopSaleMoney(){
        extract(input());
        if($r_id == ''){
            return json(['code'=>100,'msg'=>'请选择要提现的记录！']);
        }
        $ids = explode(',',$r_id);
        foreach($ids as $key=>$vo){
            $res = $this->agreeOrRefuseTixian($vo,$type,$remark);
            if($res['code'] != 200){
                return json(['code'=>100,'msg'=>'ID:'.$vo.'业务员提现失败']);
            }
        }
        return json(['code'=>200,'msg'=>'批量提现成功']);
    }

}